/*
 * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ffmpeg.ohos.sample.tests;

import net.sourceforge.sox.CrossfadeCat;
import net.sourceforge.sox.SoxController;
import ohos.app.Context;
import org.ffmpeg.ohos.ShellUtils;
import org.ffmpeg.ohos.sample.util.Log;
import org.ffmpeg.ohos.sample.util.ResUtil;

public class DemoCrossFadeCatTest {
    private final static String TAG = DemoCrossFadeCatTest.class.getSimpleName();

    public static boolean execute(Context ctx) {
        String input_audio_file_path1 = ResUtil.getMediaInputFilePath(ctx, "imperialmarch60.wav");
        String input_audio_file_path2 = ResUtil.getMediaInputFilePath(ctx, "pinkpanther60.wav");
        String output_audio_file_path = "/storage/emulated/0/Android/data/org.ffmpeg.ohos.sample/files/Music/mixedaudio.wav";
        try {
            SoxController soxc = new SoxController(ctx, null, new ShellUtils.ShellCallback() {
                @Override
                public void shellOut(String shellLine) { }

                @Override
                public void processComplete(int exitValue) {
                    Log.i(TAG, " processComplete");
                }
            });
            new CrossfadeCat(soxc, input_audio_file_path1, input_audio_file_path2, 20, output_audio_file_path).start();
            return true;
        } catch (Exception e) {
            Log.e(TAG, " Got Exception=" + e.getMessage());
            return false;
        }
    }
}
